<template>
  <div class="main">
    <div style="margin-top: 1.25rem; margin-bottom: 30px; font-weight: 600">
      <span style="font-size: 14px; color: #999">在线考试/</span
      ><span style="font-size: 14px; font-weight: 400; color: #666"
        >收藏练习</span
      >
    </div>
    <div class="banner">
      <div class="tit">收藏练习题</div>
      <div class="btn-box">
        <div class="btn-all-play">随机练习</div>
      </div>
    </div>
    <div class="main_top">
      <div style="padding: 1.25rem">收藏练习题</div>
      <!-- <div class="favorites-card" v-for="(Item,index) in CollectQuestionList" :key="Item.id">
				<div class="favorites-meta">
					<div style="font-size: 0.75rem">
						<span class="pubdate is-success" style="color: #c2c2c2;">2020-12-02 21:11:56</span>
						<span> 在《{{Item.testPaperName}}》中收藏：</span>
					</div>
					<div class="meta-title" style="margin-top: 1.625rem;cursor: pointer;">
						<a class="name ellipsis" style="display: flex;">{{index+1}}:<div v-html="`${md(Item.question.content)}`"></div></a>
					</div>
					<div class="meta-status">
						<div>

							<div style="color: #e5e5e5;"></div>
							<div style="margin-top: 0.55rem;">正确答案：{{Item.question.answer}}</div>
						</div>
						<div class="meta-view">
							<button class="el-button el-button--default" @click="collectQuestion(Item.questionId,Item.testPaperId)">
								<span>取消收藏</span>
							</button>
						</div>

					</div>


				</div>
			</div> -->
      <div class="question" v-for="(item, idx) in questions" :key="idx">
        <div>{{ `${idx + 1}.[${item.question.name}]` }}</div>
        <div style="display: flex">
          <div v-html="`${md(item.question.content)}`"></div>
        </div>
        <div>
          <div
            v-for="(Ite, index) in item.question.optionsList"
            :key="index"
            style="margin-left: 1.25rem; margin-top: 20px; display: flex"
          >
            {{ letter[index] }}:
            <div v-html="`${md(Ite.content)}`"></div>
          </div>
        </div>
		<div style="display:flex;background-color: #f9f9f9;">
        <ul style=" margin-top: 10px;width: 86%;">
          <div
            v-if="
              item.question.name == '单选题' || item.question.name == '多选题'
            "
          >
            <li>标答:{{ Anwer[idx].answer }}</li>
          </div>
          <div v-if="item.question.name == '判断题'">
            <li>标答:{{ item.question.answer == 1 ? "正确" : "错误" }}</li>
          </div>
          <div
            v-if="
              item.question.name == '填空题' || item.question.name == '简单题'
            "
          >
            <li>标答:{{ item.question.answer }}</li>
          </div>

          <li>分数：{{ item.question.score }}</li>
          <li>
            难度：<el-rate
              v-model="item.question.difficulty"
              :max="5"
              :texts="texts"
              show-text
              disabled="disabled"
            >
            </el-rate>
          </li>
        </ul>
        <div class="meta-view">
          <button
            class="el-button el-button--default"
            @click="collectQuestion(item.questionId, item.testPaperId)"
          >
            <span>取消收藏</span>
          </button>
        </div>
		</div>
      </div>
    </div>
  </div>
</template>

<script>
import marked from "marked";
import { HttpManager } from "../../request/Teacher.js";
import { TestManager } from "../../request/test.js";
export default {
  data() {
    return {
      CollectQuestionList: [],
      questions: [],
      letter: ["A", "B", "C", "D", "E", "F", "G", "H", "R", "J", "K", "L"],
      Anwer: [],
      texts: ["一星", "二星", "三星", "四星", "五星"],
    };
  },
  methods: {
    //获取收藏列表
    collectQuestionList() {
	  const loading = this.$loading({
        lock: true,
        text: "正在加载...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      var parmas = {
        currentPage: 1,
        pageSize: 100,
      };
      HttpManager.collectQuestionList(this.qs.stringify(parmas)).then((e) => {
		loading.close();
        console.log(e.data.data.dataList);
        this.questions = e.data.data.dataList;
        //获取答案
        var map = new Map();
        //存入map
        for (let i = 0; i < this.questions.length; i++) {
          if (
            this.questions[i].question.topicId == 1 ||
            this.questions[i].question.topicId == 2
          ) {
            for (
              let j = 0;
              j < this.questions[i].question.optionsList.length;
              j++
            ) {
              map.set(
                this.questions[i].question.optionsList[j].id,
                this.letter[j]
              );
              console.log(this.letter[j]);
            }
          }
          //获取标准答案
          var ans = this.questions[i].question.answer.split(",");
          var an = [];
          for (let i = 0; i < ans.length; i++) {
            console.log(ans[i]);
            console.log(map.get(parseInt(ans[i])));
            an.push(map.get(parseInt(ans[i])));
          }
          var answer = an.join(",");

          var p = { answer: answer };
          this.Anwer.push(p);
        }
        console.log(this.Anwer);
      });
    },
    md(content) {
      return marked(content);
    },
    //收藏题目
    collectQuestion(id, testPaperId) {
      var parmas = {
        questionId: id,
        testPaperId: testPaperId,
      };
      TestManager.collectQuestion(this.qs.stringify(parmas))
        .then((e) => {
          this.$message({
            message: "取消收藏成功",
            type: "success",
          });
          this.collectQuestionList();
        })
        .catch((e) => {
          this.$message({
            message: "取消收藏失败",
            type: "warning",
          });
        });
    },
  },
  created() {
    this.collectQuestionList();
  },
};
</script>

<style scoped="scoped">
.main {
  height: 100vh;
  width: 86%;
  margin-right: 7%;
  margin-left: 7%;
}

.main_top {
  margin-top: 1.25rem;
  background-color: white;
  height: 23.75rem;
  border-radius: 8px;
}

.banner {
  width: 100%;
  margin: 0 auto;
  height: 198px;
  background: linear-gradient(270deg, #c48df1, #9254de);
  box-shadow: 0 4px 8px 0 hsl(0deg 0% 40% / 10%);
  border-radius: 8px;
  margin-bottom: 30px;
  padding-top: 50px;
  box-sizing: border-box;
}

.tit {
  width: 100%;
  height: 28px;
  font-size: 20px;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: #fff;
  line-height: 28px;
  text-align: center;
  margin-bottom: 50px;
}

.btn-box {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.btn-all-play {
  width: 104px;
  height: 40px;
  background: rgb(255, 255, 255);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 400;
  color: rgb(147, 85, 222);
}

.favorites-card {
  border-bottom: 1px solid rgb(231, 231, 231);
  min-height: 96px;
  border-radius: 4px;
  background: rgb(255, 255, 255);
  padding: 24px 20px;
  margin-bottom: 0px;
  box-sizing: inherit;
  display: flex;
}

.favorites-cover {
  position: relative;
  float: left;
  border-radius: 4px;
  overflow: hidden;
  width: 154px;
  height: 96px;
  margin-right: 24px;
  box-sizing: inherit;
}

.favorites-cover img {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  box-sizing: inherit;
  border-style: none;
}

.meta-footer {
  display: flex;
  font-size: 16px;
  box-sizing: inherit;
}

.meta-status {
  padding: 16px 0px 20px;
  font-size: 14px;
  color: rgb(80, 80, 80);
  line-height: 16px;
  display: flex;
  justify-content: space-between;
}

.favorites-meta {
  width: 95%;
}

.meta-view {
  margin-left: 2.25rem;
  text-align: center;
  margin-top: 40px;
}

.meta-title {
  /* height: 24px; */
  line-height: 24px;
  box-sizing: inherit;
}

.meta-footer {
  font-size: 16px;
  box-sizing: inherit;
}
.question {
  flex: 5;
  display: flex;
  flex-direction: column;
  padding: 50px;
  border-bottom: 1px solid #dfdfdf;
  background: white;
}
.question li {
  list-style: none;
  display: block;
  height: 40px;
  margin-left: 1.875rem;
  display: flex;
  align-items: center;
}

.question span {
  display: inline-block;
  height: 20px;
  padding: 2px 5px;
  border-radius: 3px;
  border: 1px solid #fdf6ec;
}

.question .yes {
  background: #f0f9eb;
  color: #97d3bf;
}

.question .no {
  background-color: #fdf6ec;
  color: #e7ac95;
}

.left {
  margin-top: 3.25rem;
  background-color: #ffffff;
  width: 100px;
  text-align: center;
}

.left div {
  margin-top: 0.875rem;
}

.Bottom {
  position: absolute;
  bottom: 0;
  overflow: hidden;
  display: flex;
}
</style>
